"""
@ProjectName : CourseManagementSystem
@File        : course_service.py
@Author      : WorldWind(1772830365@qq.com)
@Address     : ChangSha - BoWeiFeng
@Date        : 2025/7/17 下午1:35
"""
from courses.course import Course
from courses.course_db import CourseDB


class CourseService:
    def __init__(self):
        self.courseDB = CourseDB()
        print(f'This is __init__ method. {self.get_class_name()} class startup')

    # 新增课程
    def add(self, course):
        return self.courseDB.add(course)

    def delete(self, id):
        return self.courseDB.delete(id)

    def update(self, course):
        return self.courseDB.update(course)

    def searchAll(self):
        return self.courseDB.searchAllCourses()

    def searchCourseByName(self, course_name):
        return self.courseDB.searchByCoursename(course_name)

    @classmethod
    def get_class_name(cls):
        return cls.__name__

    def __del__(self):
        print(f'This is __del__ method. The {self.get_class_name()} class has been recycled')


if __name__ == '__main__':
    courseService = CourseService()
    course = Course()
    course.course_no = 'c007'
    course.course_name = '程序设计'
    course.max_score = 100
    course.min_sorce = 60
    print(courseService.add(course))
